<route lang="json5" type="page">
{
  style: {
    navigationBarTitleText: '',
    navigationBarTextStyle: '#000000',
    navigationStyle: 'custom',
    navigationBarBackgroundColor: '#ffffff',
  },
}
</route>

<template>
  <view class="content">
    <wd-card v-for="(item, index) in dataList" :key="index">
      <view>
        <template #title>
          <view class="dataTopBox mb-[20upx]">
            <view>{{ item.facilityNo }}</view>
          </view>
        </template>
        <view class="allInfo mb-[20upx]">
          <view class="item">
            <view class="w-[130upx] mr-[30upx]">设施确认:</view>
            <view>
              <wd-radio-group shape="dot" v-model="item.facilitySure" inline>
                <wd-radio :value="0">是</wd-radio>
                <wd-radio :value="1">否</wd-radio>
              </wd-radio-group>
            </view>
          </view>
          <view class="item">
            <view class="mr-[30upx] w-[130upx]">设施清洁:</view>
            <view>
              <wd-radio-group shape="dot" v-model="item.cleanResult" inline>
                <wd-radio :value="0">是</wd-radio>
                <wd-radio :value="1">否</wd-radio>
              </wd-radio-group>
            </view>
          </view>
          <view class="item mt-[20upx]">
            <view class="mr-[30upx] w-[130upx]">图片:</view>
            <view>
              <wd-upload
                v-model:file-list="item.fileList"
                :size-type="['compressed']"
                reupload
                :limit="1"
                :action="action"
              ></wd-upload>
            </view>
          </view>
        </view>
      </view>
    </wd-card>
    <view class="bottomBox">
      <wd-button plain @click="goBack">取消</wd-button>
      <wd-button @click="sureSubmit">确认</wd-button>
    </view>
  </view>
</template>

<script lang="js" setup>
import { onLoad, onReachBottom, onPageScroll } from '@dcloudio/uni-app'
import { useCleaningStore } from '@/store'
import { postCheckOutConfirm } from '@/api/cleaning/checkOutConfirm.js'

defineOptions({
  name: 'ConfirmSure',
})

const cleaningStore = useCleaningStore()
const action = ref(import.meta.env.VITE_UPLOAD_BASEURL)
const dataList = ref([])

onMounted(() => {
  uni.setNavigationBarTitle({
    title: `退房确认-${cleaningStore.roomName}`,
  })
  dataList.value = cleaningStore.facilityList.map((item) => {
    return {
      ...item,
      fileList: [],
      facilitySure: 0,
      cleanResult: 0,
    }
  })
})

// 点击返回
const goBack = () => {
  uni.navigateBack()
}

// 点击确认
const sureSubmit = async () => {
  let code = true
  dataList.value.forEach((item) => {
    if (item.fileList.length == 0) {
      code = false
    }
  })
  if (!code) {
    uni.showToast({ title: '请上传清洁图片', icon: 'none' })
    return
  }
  const res = await postCheckOutConfirm({
    facilityIdList: dataList.value.map((item) => {
      return {
        ...item,
        cleanPic: item.fileList[0].response,
      }
    }),
  })
  if (res.data.code == 200) {
    uni.showToast({ title: '提交成功', icon: 'none' })
    uni.navigateBack()
  }
}
</script>
<style lang="scss" scoped>
:deep() {
  .wd-card__title-content {
    padding: 14upx 0upx !important;
  }
  .wd-card__footer {
    padding: 14upx 0upx !important;
  }
}
.content {
  min-height: 100vh;
  padding-top: 30upx;
  background-color: #f1f1f1;
  padding-bottom: 200upx;
  .dataTopBox {
    display: flex;
    font-size: 32upx;
    color: black;
    justify-content: space-between;
    align-items: center;
    .time {
      color: #a9a8a8;
      font-size: 24upx;
    }
  }
  .allInfo {
    padding-left: 30upx;
    .item {
      display: flex;
      align-items: center;
      min-height: 60upx;
    }
  }
  .bottomBox {
    height: 180upx;
    background-color: white;
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0px 30px;
    box-sizing: border-box;
  }
}
</style>
